package models

import (
	"github.com/spf13/cast"
	"gorm.io/gorm"
)

// 模型基类
type BaseModel struct {
	ID uint64 `gorm:"column:id;primary_key;auto_increment" json:"id,omitempty"`
}

// 时间戳字段
type CommonTimestampsField struct {
	CreatedAt Time `gorm:"column:created_at;type:timestamp;" json:"created_at,omitempty"`
	UpdatedAt Time `gorm:"column:updated_at;type:timestamp;" json:"updated_at,omitempty"`
}

// 删除字段时间
type DeletedAtTimestampsField struct {
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;" json:"-"`
}

// 获取 ID 的字符串格式
func (a BaseModel) GetStringID() string {
	return cast.ToString(a.ID)
}

// 获取更新时间
func (a CommonTimestampsField) GetUpdateAt() string {
	return Time.String(a.UpdatedAt)
}
